package com.lmk.mkcc.mq.producer;

import com.lmk.mkcc.domain.MediaFile;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.client.producer.SendStatus;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

@Component
public class PushVideoProducer {
    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    public boolean sendmessage(MediaFile mediaFile){
        // 创建一个message消息对象
        Message<MediaFile> message = MessageBuilder.withPayload(mediaFile).build();
        // 发送同步消息
        SendResult sendResult = rocketMQTemplate.syncSend("topic-coursevideo:tag-coursevideopush", message);
        // 获取发送状态
        SendStatus status = sendResult.getSendStatus();
        return status==SendStatus.SEND_OK?true:false;

    }

}
